package lab02.test36;

import java.util.Arrays;
import java.util.Scanner;

public class Test36 {

    public static void main(String[] args) {

        Scanner scanner = new Scanner(System.in);
        Student[] student = new Student[5];
        Student[] newstudent = new Student[5];

        student[0] = new Undergraduate("张三");
        student[1] = new Undergraduate("李四");
        student[2] = new Undergraduate("赵六");
        student[3] = new Postgraduate("王五");
        student[4] = new Postgraduate("陈七");
        try {
            for (int i = 0; i < student.length; i++) {
                System.out.println("输入" + student[i].getName() + "的第几门课 及这门课的成绩：");
                student[i].setCoursesgrade(scanner.nextInt() - 1, scanner.nextInt());
                student[i].setCoursesgrade(scanner.nextInt() - 1, scanner.nextInt());
                student[i].setCoursesgrade(scanner.nextInt() - 1, scanner.nextInt());
                student[i].graderank();
            }
            for (int i = 0; i < student.length; i++) {
                newstudent[i] = student[i];
            }

            for (int i = 0; i < student.length; i++) {
                for (int j = 0; j < student.length - i - 1; j++) {
                    if (student[j].aver < student[j + 1].aver) {

                        newstudent[j] = student[j + 1];
                        newstudent[j + 1] = student[j];

                    }
                }
            }

            System.out.println("姓名 " + "\t" + " 类型 " + "\t" + " 成绩");

            for (int i = 0; i < student.length; i++) {
                System.out.println(newstudent[i].getName() + "\t" + newstudent[i].getDept() + "\t" + newstudent[i].getGradeRank());
            }

        } catch (ArrayIndexOutOfBoundsException a) {
            System.out.println("数组越界");
        }

    }
}
